﻿using System.Drawing;
using System.IO;
using NUnit.Framework;

namespace PhotoFramePublishingPlugin.Tests
{
    [TestFixture]
    public class PublishPluginPublishItemTests
    {
        [Test]
        public void PublishItemInternal_WithPortraitImage_WithLandscapeDimensions_WithAddBorders_WritesCorrectSizeImageWithBorders()
        {
            const bool shouldAddBorders = true;
            Stream sourceStream = File.OpenRead(@"Images\Portrait480.png");
            Stream destinationStream = new MemoryStream();

            PublishPlugin.PublishItemInternal(shouldAddBorders, Color.Blue, sourceStream, 640, 480, destinationStream);

            destinationStream.Position = 0;
            Image destinationImage = Image.FromStream(destinationStream);

            Assert.AreEqual(640, destinationImage.Width);
            Assert.AreEqual(480, destinationImage.Height);
        }

        [Test]
        public void PublishItemInternal_WithPortraitImage_WithLandscapeDimensions_WithoutAddBorders_WritesCorrectSizeImageWithBorders()
        {
            const bool shouldAddBorders = false;
            Stream sourceStream = File.OpenRead(@"Images\Portrait480.png");
            Stream destinationStream = new MemoryStream();

            PublishPlugin.PublishItemInternal(shouldAddBorders, Color.Blue, sourceStream, 640, 480, destinationStream);

            destinationStream.Position = 0;
            Image destinationImage = Image.FromStream(destinationStream);

            Assert.AreEqual(360, destinationImage.Width);
            Assert.AreEqual(480, destinationImage.Height);
        }

        [Test]
        public void PublishItemInternal_WithLandscapeImage_WithLandscapeDimensions_WithAddBorders_WritesCorrectSizeLandscapeImage()
        {
            const bool shouldAddBorders = true;
            Stream sourceStream = File.OpenRead(@"Images\Landscape640.png");
            Stream destinationStream = new MemoryStream();

            PublishPlugin.PublishItemInternal(shouldAddBorders, Color.Blue, sourceStream, 640, 480, destinationStream);

            destinationStream.Position = 0;
            Image destinationImage = Image.FromStream(destinationStream);

            Assert.AreEqual(640, destinationImage.Width);
            Assert.AreEqual(480, destinationImage.Height);
        }

        [Test]
        public void PublishItemInternal_WithLandscapeImage_WithLandscapeDimensions_WithoutAddBorders_WritesCorrectSizeLandscapeImage()
        {
            const bool shouldAddBorders = true;
            Stream sourceStream = File.OpenRead(@"Images\Landscape640.png");
            Stream destinationStream = new MemoryStream();

            PublishPlugin.PublishItemInternal(shouldAddBorders, Color.Blue, sourceStream, 640, 480, destinationStream);

            destinationStream.Position = 0;
            Image destinationImage = Image.FromStream(destinationStream);

            Assert.AreEqual(640, destinationImage.Width);
            Assert.AreEqual(480, destinationImage.Height);
        }
    }
}
